package exam.huawei.S1;

import java.util.*;

/**
 * 注意点：
 * 1、经典回溯，使用dfs，配置方案用path来记录
 * 2、将servers倒序排列，由大到小遍历，那么最终的配置方案列表就是升序排序的，不用再做任何处理
 * 3、剪枝策略，如果当前算力超过target或者服务器num超过minNum，则直接return
 * 4、最终方案列表result，需要根据minNum和num的大小来更新。如果num < minNum，则需要将result先clear
 * 5、打印最终方案列表时，对于每个方案，都要升序打印
 */
public class Main {

    public static int[] servers;
    public static int target;
    public static int minNum = Integer.MAX_VALUE;
    public static List<int[]> result = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] ss = s.split(" ");
        servers = new int[ss.length];
        for (int i = 0; i < ss.length; i++)
            servers[i] = Integer.parseInt(ss[i]);
        target = sc.nextInt();
        solution();
    }

    private static void solution() {
        Arrays.sort(servers);
        dfs(new ArrayList<>(), servers.length-1, 0);
        if (result.size() == 0)
            System.out.println(-1);
        else {
            for (int i = 0; i < result.size(); i++) {
                int[] arr = result.get(i);
                Arrays.sort(arr);
                for (int j = 0; j < arr.length; j++) {
                    if (j > 0)
                        System.out.print(" ");
                    System.out.print(arr[j]);
                }
                System.out.println();
            }
        }
    }

    private static void dfs(List<Integer> path, int cur, int sum) {
        if (sum > target || path.size() > minNum)
            return;
        if (sum == target) {
            int[] temp = new int[path.size()];
            for (int i = 0; i < path.size(); i++)
                temp[i] = path.get(i);
            if (path.size() < minNum) {
                minNum = path.size();
                result.clear();
            }
            result.add(temp);
            return;
        }
        for (int i=cur; i>=0; --i) {
            path.add(servers[i]);
            dfs(path, i, sum + servers[i]);
            path.remove(path.size()-1);
        }
    }
}
